package com.quanyan.place.task.tracker;

import com.github.ltsopensource.core.domain.Action;
import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.tasktracker.Result;
import com.github.ltsopensource.tasktracker.runner.JobContext;
import com.github.ltsopensource.tasktracker.runner.JobRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xian-guo
 */
public class TaskJobRunner implements JobRunner {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskJobRunner.class);
    @Autowired
    private JobRunnerPlacePeriodSeaArea jobRunnerPlacePeriodSeaArea;

    @Autowired
    OrderCompleteStatusCheckTask orderCompleteStatusCheckTask;

    @Autowired
    JobRunnerPlaceFinanceData jobRunnerPlaceFinanceData;

    @Autowired
    JobRunnerPlaceContractData jobRunnerPlaceContractData;

    @Autowired
    SyncPlaceSalePlan syncPlaceSalePlan;

    @Autowired
    UpdatePlaceIndex updatePlaceIndex;
    
    @Autowired
    PlaceWonderfulActivityTask placeWonderfulActivityTask;

    @Autowired
    UpdateBlockBookingStatus updateBlockBookingStatus;

    @Autowired
    SyncPlaceInfoSolrTask syncPlaceInfoSolrTask;

    @Autowired
    PlacePromoteAccountTask placePromoteAccountTask;

    @Autowired
    PlacePoolOrderAccountTask placePoolOrderAccountTask;
	
	@Autowired
    PlacePromoteRewardSettleTask placePromoteRewardSettleTask;

    @Autowired
    PlaceCashOrderAccountTask placeCashOrderAccountTask;

    @Autowired
    ShoppingCartOrderCheckTask shoppingCartOrderCheckTask;


    @Override
    public Result run(JobContext jobContext) throws Throwable {
            LOGGER.info("------TaskJobRunner执行了---------" + jobContext);
            Job job=jobContext.getJob();//对于需要执行多个任务的业务场景，可以使用这种方式
            String jobType=job.getParam("type");
            switch (jobType){
                case "placePeriodSeaArea" : return jobRunnerPlacePeriodSeaArea.run(jobContext);
                case "placeFinanceData" : return jobRunnerPlaceFinanceData.run(jobContext);
                case "contractPlaceData" : jobRunnerPlaceContractData.run(jobContext);
                case "orderCompleteStatusCheckTask" : return orderCompleteStatusCheckTask.run(jobContext);
                case "syncPlaceSalePlan" : return syncPlaceSalePlan.run(jobContext);
                case "updatePlaceIndex" : return updatePlaceIndex.run(jobContext);
                case "updateBlockBookingStatus" : return updateBlockBookingStatus.run(jobContext);
                case "syncPlaceInfoToSolr" : return syncPlaceInfoSolrTask.run(jobContext);
                case "placePromoteAccount": return placePromoteAccountTask.run(jobContext);
                case "placeCashOrderAccountTask": return placeCashOrderAccountTask.run(jobContext);
                case "placePoolOrderAccount": return placePoolOrderAccountTask.run(jobContext);
                case "placePromoteRewardSettleTask": return placePromoteRewardSettleTask.run(jobContext);
                case "placeWonderfulActivity": return placeWonderfulActivityTask.run(jobContext);
                case "shoppingCartOrderCheckTask": return shoppingCartOrderCheckTask.run(jobContext);
                default: return new Result(Action.EXECUTE_SUCCESS, "-------当前没有可执行的任务---------------");
            }
    }

}
